package model;

/**
 * This Enumeration represents all the timeslots
 * that employees may be scheduled in and will be
 * used for easy comparisons during schedule
 * construction.
 * 
 * @author Tristan D. Boucher
 * @version Commit #12 9/7/2013
 * 
 */
public enum TimeSlot 
{
  
  /**
   * Default TimeSlot. Empty.
   */
  EMPTY(0),

  /**
   * TimeSlot @ 7:00am - 7:30am. 
   */
  SLOT_0(700),

  /**
   * TimeSlot @ 7:30am - 8:30am.  
   */
  SLOT_1(730),

  /**
   * TimeSlot @ 8:30am - 9:30am.  
   */
  SLOT_2(830),

  /**
   * TimeSlot @ 9:30am - 10:30am.  
   */
  SLOT_3(930),

  /**
   * TimeSlot @ 10:30am - 11:30am. 
   */
  SLOT_4(1030),

  /**
   * TimeSlot @ 11:30am - 12:30am.
   */
  SLOT_5(1130),

  /**
   * TimeSlot @ 12:30am - 1:30pm. 
   */
  SLOT_6(1230),

  /**
   * TimeSlot @ 1:30pm - 2:30pm. 
   */
  SLOT_7(1330),

  /**
   * TimeSlot @ 2:30pm - 3:00pm.  
   */
  SLOT_8(1430),

  /**
   * TimeSlot @ 3:00pm - 4:00pm.   
   */
  SLOT_9(1500),

  /**
   * TimeSlot @ 4:00pm - 5:00pm. 
   */
  SLOT_10(1600),

  /**
   * TimeSlot @ 5:00pm - 6:00pm. 
   */
  SLOT_11(1700),

  /**
   * TimeSlot @ 6:00pm - 7:00pm. 
   */
  SLOT_12(1800),

  /**
   * TimeSlot @ 7:00pm - 8:00pm. 
   */
  SLOT_13(1900),

  /**
   * TimeSlot to signify the end of the day at 8pm.
   */
  SLOT_DAY_END(2000);

  //Fields
  /**
   * The constant that lists all of the available time slots.
   */
  private static final TimeSlot[] MY_SLOTS = {TimeSlot.SLOT_0,
                                              TimeSlot.SLOT_1,
                                              TimeSlot.SLOT_2,
                                              TimeSlot.SLOT_3,
                                              TimeSlot.SLOT_4,
                                              TimeSlot.SLOT_5,
                                              TimeSlot.SLOT_6,
                                              TimeSlot.SLOT_7,
                                              TimeSlot.SLOT_8,
                                              TimeSlot.SLOT_9,
                                              TimeSlot.SLOT_10,
                                              TimeSlot.SLOT_11,
                                              TimeSlot.SLOT_12,
                                              TimeSlot.SLOT_13};
  /**
   * True if preferred timeslot. False if simply available but
   * unpreferred timeslot.
   */
  private boolean my_preferred_slot;
  
  /**
   * The number corresponding to a particular Classes value.
   */
  private int my_index;
  
  
  // Constructor
  /**
   * Constructs a new Class with the specified index. 
   * In this case the numbers are the class indexes such as
   * Math 238 is Differential Equations. So the index for 
   * D.E. is 238.
   * 
   * @param the_index my_index.
   */
  private TimeSlot(final int the_index)
  {
    my_index = the_index;
    my_preferred_slot = false;
  }

  // Instance Methods

  /**
   * Toggles my_preferred_slot.
   * 
   * @param the_choice true or false.
   */
  public void setPreferred(final boolean the_choice)
  {
    my_preferred_slot = the_choice;
  }
  
  /**
   * Returns the Class represented by the given number index.
   * 
   * @param the_index The index of the Class to return. 
   * @return the day represented by the given index. If the
   * index is not recognizable, the default is algebra.
   */
  public static TimeSlot valueOf(final char the_index)
  {
    TimeSlot result = EMPTY;

    for (TimeSlot slot : TimeSlot.values())
    {
      if (slot.my_index == the_index)
      {
        result = slot;
        break;
      }
    }

    return result;
  }
  
  /**
   * Returns whether this slot is preferred or not.
   * 
   * @return my_preferred slot True if preferred hours.
   * False if not.
   */
  public boolean isPreferred()
  {
    return my_preferred_slot;
  }

  /**
   * Returns whether this slot is empty or not.
   * 
   * @return true if equal to empty, false otherwise.
   */
  public boolean isEmpty()
  {
    boolean to_return = false;
    
    if (this == EMPTY)
    {
      to_return = true;
    }
    return to_return;
  }
  
  /**
   * Returns all of the timeslot types in a timeslot array.
   * 
   * @return MY_SLOTS all the timeslot variables.
   */
  public static TimeSlot[] getAllSlots()
  {
    return MY_SLOTS.clone();
  }
  
  /** 
   * Returns a String representation of this Class such as "Calculus_4 (254)".
   * 
   * @return a String representation of this Class.
   */
  public String toString()
  {
    return my_index + ":";
  }
}
// end of Enumeration TimeSlot